﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBA.Common;
using DBA.Data;
using DBA.Data.ADO;
using DBA.Model;
using DBA.Web.UI;
using DBA.Bll;

namespace DBA.Web.StudentManage
{
    public partial class EducationManage : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;

            SetCondition();
        }

        private void SetCondition()
        {
            IList<AdoCondition> dict = new List<AdoCondition>();
            if (!VerificationHelper.IsNullOrEmpty<string>(txt_UserName.Text))
            {
                dict.Add(new AdoCondition(CompareOper.like, LogicOper.and, "UserName", txt_UserName.Text));
            }
            if (!VerificationHelper.IsNullOrEmpty<string>(txt_BeginTime_s.Text))
            {
                dict.Add(new AdoCondition(CompareOper.notLessThan, LogicOper.and, "BeginTime", txt_BeginTime_s.Text, "BeginTime_s"));
            }
            if (!VerificationHelper.IsNullOrEmpty<string>(txt_BeginTime_e.Text))
            {
                dict.Add(new AdoCondition(CompareOper.notMoreThan, LogicOper.and, "BeginTime", txt_BeginTime_e.Text, "BeginTime_e"));
            }
            if (ddl_UserType.Text!="-1")
            {
                dict.Add(new AdoCondition(CompareOper.like, LogicOper.and, "UserType", ddl_UserType.SelectedValue));
            }
            if (!VerificationHelper.IsNullOrEmpty<string>(txt_EndTime_s.Text))
            {
                dict.Add(new AdoCondition(CompareOper.notLessThan, LogicOper.and, "EndTime", txt_EndTime_s.Text, "EndTime_s"));
            }
            if (!VerificationHelper.IsNullOrEmpty<string>(txt_EndTime_e.Text))
            {
                dict.Add(new AdoCondition(CompareOper.notMoreThan, LogicOper.and, "EndTime", txt_EndTime_e.Text, "EndTime_e"));
            }

            dict.Add(new AdoCondition("BeginTime", OrderTypes.desc));
            dict.Add(new AdoCondition("EndTime", OrderTypes.desc));
            dict.Add(new AdoCondition("Id", OrderTypes.desc));

            //dict.Add(new AdoCondition(CompareOper.equal, LogicOper.and, "EmployeeID", "20"));
            //dict.Add(new AdoCondition(CompareOper.equal, LogicOper.and, "sam", "20"));

            ViewState["conditions"] = dict;
            Bind(1, dict);
        }

        DataAccessLibrary dal = CommonQuery.DataAccessLibrary;

        protected void linkBtnSearch_Click(object sender, EventArgs e)
        {
            SetCondition();
        }

        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            IList<AdoCondition> dict = null;
            if (ViewState["conditions"] != null)
            {
                dict = (IList<AdoCondition>)ViewState["conditions"];
            }
            Bind(e.NewPageIndex, null);
        }

        private void Bind(int pageIdx, IList<AdoCondition> conditionList)
        {
            int iCount = 0;
            replData.DataSource = dal.ModifyData.Select<Vw_EducationInfo>(conditionList, pageIdx, 10, ref iCount);
            replData.DataBind();
            AspNetPager1.RecordCount = iCount;

        }

        protected void linkBtnMaskSearch_Click(object sender, EventArgs e)
        {
            //IDictionary<String, String> dict = new Dictionary<String, String>();
            //dict.Add("UserName", txtMaskMemberId.Text.Trim());
            //ViewState["conditions"] = dict;
            //Bind(1, dict);
        }

        protected void lnkDownload_Click(object sender, EventArgs e)
        {
            BLLEducationInfo bllEducationInfo = new BLLEducationInfo();
            NPOIHelper.ExportByWeb(bllEducationInfo.GetEducationInfoExcel(), string.Empty, "学生进修信息" + new Random().Next().ToString() + ".xls");
        }

        protected void linkBtnDeleSelect_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(hidDeleString.Value))
            {
                string value = hidDeleString.Value;
                IList<AdoCondition> delCollections = new List<AdoCondition>();
                delCollections.Add(new AdoCondition(CompareOper.IN, LogicOper.and, "Id", value));
                int reValue = dal.ModifyData.Delete<Em_Study>(delCollections);
                if (reValue == 1)
                {
                    Bind(1, null);
                    ScriptManager.RegisterStartupScript(this, base.GetType(), "deleOk" + System.Guid.NewGuid().ToString(), "parent.alertMsg.correct('数据删除成功');", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, base.GetType(), "deleOk" + System.Guid.NewGuid().ToString(), "parent.alertMsg.error('数据删除失败');", true);
                }
            }
        }

    }
}